<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>课程计划添加</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="./css/x-admin.css" media="all">
</head>
<body>
	<div class="x-nav">
		<span class="layui-breadcrumb"> <a><cite>首页</cite></a> <a><cite>课程管理</cite></a>
			<a><cite>课程计划信息</cite></a> <a><cite>课程计划信息添加</cite></a>
		</span> <a class="layui-btn layui-btn-small"
			style="line-height: 1.6em; margin-top: 3px; float: right"
			href="javascript:location.replace(location.href);" title="刷新"><i
			class="layui-icon" style="line-height: 30px">ဂ</i></a>
	</div>
	<div class="x-body">
		<div class="layui-tab layui-tab-brief">
			<div class="layui-tab-content">
				<div class="layui-tab-item layui-show">
					<form class="layui-form layui-form-pane">
						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>课程名称
							</label>
							<div class="layui-input-block">
								<select id="courseNo" name="courseNo">
								</select>
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>教员号
							</label>
							<div class="layui-input-block">
								<select name="teacherNo" id="teacherNo"></select>
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>开始时间
							</label>
							<div class="layui-input-block">
								<input type="date" id="courseStart" name="courseStart"
									autocomplete="off" placeholder="" class="layui-input">
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>结束时间
							</label>
							<div class="layui-input-block">
								<input type="date" id="courseEnd" name="courseEnd"
									autocomplete="off" placeholder="" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>上课人数
							</label>
							<div class="layui-input-block">
								<input type="number" id="courseNum" name="courseNum"
									autocomplete="off" placeholder="请输入数字" min="1"
									class="layui-input">
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>上课地点
							</label>
							<div class="layui-input-block">
								<input type="text" id="coursePlace" name="coursePlace"
									autocomplete="off" placeholder="请输入文字" class="layui-input">
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>上课时间
							</label>
							<div class="layui-input-block">
								<input type="text" id="courseTime" name="courseTime"
									autocomplete="off" placeholder="格式为:8:00-16:00"
									class="layui-input">
							</div>
						</div>

						<div class="layui-form-item">
							<label class="layui-form-label"> <span class='x-red'>*</span>课程状态
							</label>
							<div class="layui-input-block">
								<select name="courseStatus" id="courseStatus">
									<option value="1">招募中</option>
									<option value="2">开课中</option>
									<option value="3">已结课</option>
									<option value="4">已取消</option>
									<option value="5">已满员</option>
								</select>
							</div>
						</div>

						<div class="layui-form-item">
							<button id="but" class="layui-btn" lay-submit="" lay-filter="add">
								添加</button>
						</div>
					</form>
					<div style="height: 100px;"></div>
				</div>
			</div>
		</div>
	</div>
	<script src="./lib/layui/layui.js" charset="utf-8"></script>
	<script src="./js/x-layui.js" charset="utf-8"></script>
	<script src="js/jquery-2.0.3.js"></script>
	<script>
		$(function() {
			$.get("CourseServlet?op=ajaxReq", function(data) {
				$.each(data, function(index, course) {
					$("#courseNo").append(
							"<option value="+course.courseNo+">"
									+ course.courseName + "</option>");
				});
			});
			$.get("TeachServlet?op=ajaxReq", function(data) {
				$.each(data, function(index, teacher) {
					$("#teacherNo").append(
							"<option value="+teacher.teacherNo+">"
									+ teacher.teacherNo + "</option>");
				});
			});
		});

		layui.use([ 'element', 'layer', 'form' ], function() {
			$ = layui.jquery;//jquery
			lement = layui.element();//面包导航
			layer = layui.layer;//弹出层
			form = layui.form()

			//监听提交
			form.on('submit(add)', function(data) {
				var courseNo = $("#courseNo").val();
				var teacherNo = $("#teacherNo").val();
				var courseStart = $("input[name='courseStart']").val();
				var courseEnd = $("input[name='courseEnd']").val();
				var courseNum = $("input[name='courseNum']").val();
				var coursePlace = $("input[name='coursePlace']").val();
				var courseTime = $("input[name='courseTime']").val();
				var courseStatus = $("#courseStatus").val();

				if (courseStart == "") {
					layer.msg('开始时间不能为空', {
						icon : 5,
						time : 2000
					});
					return false;
				}
				if (courseEnd == "") {
					layer.msg('结束时间不能为空', {
						icon : 5,
						time : 2000
					});
					return false;
				}
				if (courseNum == "") {
					layer.msg('上课人数不能为空', {
						icon : 5,
						time : 2000
					});
					return false;
				}
				if (coursePlace == "") {
					layer.msg('上课地点不能为空', {
						icon : 5,
						time : 2000
					});
					return false;
				}
				if (courseTime == "") {
					layer.msg('上课时间不能为空', {
						icon : 5,
						time : 2000
					});
					return false;
				}
				
				//添加操作
				$.ajax({
					type : "get",
					url : "CoursePlanServlet",
					data : {
						courseNo : courseNo,
						teacherNo : teacherNo,
						courseStart : courseStart,
						courseEnd : courseEnd,
						courseNum : courseNum,
						coursePlace : coursePlace,
						courseTime : courseTime,
						courseStatus : courseStatus,
						op : "add"
					},
					dataType : "json",
					success : function(data) {
						if (data.code == 1) {
							layer.msg(data.msg, {
								icon : 6,
								time : 2000
							}, function() {
								window.parent.location.reload();
								var index = parent.layer
										.getFrameIndex(window.name);
								parent.layer.close(index);
							});
							return false;

						} else {
							layer.msg(data.msg, {
								icon : 5,
								time : 2000
							});
							return false;
						}
					}

				});
				return false;
			});
		})
	</script>
</body>
</html>